<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class UserController extends Controller
{
	//展示后台首页
	public $assign = [];
	//搜索
	public function index1(Request $request)
	{
		$in_search = $request->in_search;
		$admins_model = new \App\Model\Admins();
		$info = $admins_model->getAdmins($in_search);
		$arr['in_search'] = $in_search;
		$this->assign['info'] = $info;
		$this->assign['arr'] = $arr;
		return view('admin.index1',$this->assign);
	}
	//首页左侧栏目里的内部连接加载的页面(做兼容处理的)
	public function dashboard()
	{
		return view('admin.dashboard',$this->assign);
	}
	//添加
	public function add()
	{
		return view('admin.add',$this->assign);
	}
	public function doadd(Request $request)
	{
		$arr = $request->all();
		$name = $arr['name'];
		$phone = $arr['phone'];
		$address = $arr['address'];
		$createtime = date('Y-m-d H:i;s',time());
		$lastdotime = date('Y-m-d H:i;s',time());
		$admin_model = new \App\Model\Admins();
		$data = $admin_model->addOne($name,$phone,$address,$createtime,$lastdotime);
		if(!empty($data))
		{
			echo '<script>alert("添加文章成功");window.location.href="/admin/index1";</script>';
			// return redirect('/admin/index1');
		}
	}
	//删除
	public function del(Request $request){
		$id = $request->post('id');
		$admin_model = new \App\Model\Admins();
		$data = $admin_model->delOne($id);
	}
	//修改
	public function edit($id){
		$admin_model = new \App\Model\Admins;
		$arr = $admin_model->getOneById($id);
		$this->assign['arr'] = $arr;
		return view('/admin/edit',$this->assign);
	}

	public function doedit(Request $request,$id){
		$info = $request->all();
		$name = $info['name'];
		$phone = $info['phone'];
		$address = $info['address'];
		$lastdotime = date('Y-m-d H:i;s',time());
		$admin_model = new \App\Model\Admins;
		$arr = $admin_model->renew($id,$name,$phone,$address,$lastdotime);
		if($arr == 1){
			echo "<script>alert('修改成功');window.location.href='/admin/index1';</script>";
		}else{
			echo "<script>alert('修改失败');window.location.href='/admin/edit';</script>";
		}
	}

	//搜索
	public function search(Request $request){
		$in_search = $request->in_search;
		$admin_model = new \App\Model\Admins;
		$info = $admin_model->getAdmins($in_search);

		$this->assign['info'] = $info;
		return view('admin.index1',$this->assign);
	}

}













?>